package com.itheima.publisher.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Slf4j
@Configuration
@RequiredArgsConstructor//用于自动为类中所有带有 final 修饰的字段生成构造方法。
public class MqConfig {

    private final RabbitTemplate rabbitTemplate;

    @PostConstruct//在当前Bean初始化后回执信当前方法
    public void init() {
        rabbitTemplate.setReturnsCallback(returned -> {
            log.error("监听到消息return callback");
            log.debug("交换机:{}",returned.getExchange());
            log.debug("routingKey:{}",returned.getRoutingKey());
            log.debug("message:{}",returned.getMessage());
            log.debug("replyCode:{}",returned.getReplyCode());
            log.debug("replyTest:{}",returned.getReplyText());
        });
    }



}
